//
//  BCOderDetailView.m
//  BangcaiDriver
//
//  Created by apple on 16/9/22.
//  Copyright © 2016年 BC. All rights reserved.
//

#import "BCOderDetailView.h"
#import "BCOrderDetailCell.h"
@interface BCOderDetailView ()<UITableViewDelegate, UITableViewDataSource>
{
    UILabel *dateLab ;
    UIImageView *position;
    UILabel *titleLab;
    UILabel *distLab;
    UILabel *titleLine;
    UILabel *prcice;
    UILabel *orderNumLab;
    UILabel *amountLab;
    UILabel *weightLab;
    UILabel *widLine;
    
    UILabel *lastLab;
    UILabel *nextLab;
    UIImageView *lastArrow;
    UIImageView *nextArrow;
    UIButton *lastBut;
    UIButton *nextBut;
    

}
@property(nonatomic, strong)UITableView *dataTable;
@property(nonatomic, strong)UIView *headView;
@property(nonatomic, strong)UIView *footView;

@end

@implementation BCOderDetailView

- (void)createView
{
    self.dataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 167)];
    self.footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 65)];
    self.dataTable.tableHeaderView = self.headView;
    self.dataTable.tableFooterView = self.footView;
    self.dataTable.delegate = self;
    self.dataTable.dataSource = self;
    [self createHeadView];
    [self createFootView];
    [self.dataTable registerClass:[BCOrderDetailCell class] forCellReuseIdentifier:@"reuse"];
    [self addSubview:self.dataTable];
    
    
    
}

- (void)createFootView{
    lastLab = [[UILabel alloc] init];
    nextLab = [[UILabel alloc] init];
    lastArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"左"]];
    nextArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右"]];
    lastBut = [UIButton buttonWithType:UIButtonTypeSystem];
    nextBut = [UIButton buttonWithType:UIButtonTypeSystem];
    
    lastLab.text = @"上一单";
    lastLab.textColor = [UIColor colorWithRed:0.518 green:0.518 blue:0.518 alpha:1];
    lastLab.font = [UIFont boldSystemFontOfSize:16];
    
    nextLab.text = @"下一单";
    nextLab.textColor = [UIColor colorWithRed:0.518 green:0.518 blue:0.518 alpha:1];
    nextLab.font = [UIFont boldSystemFontOfSize:16];
    
    [lastBut addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [nextBut addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.footView addSubview:lastLab];
    [self.footView addSubview:nextLab];
    [self.footView addSubview:lastArrow];
    [self.footView addSubview:nextArrow];
    [self.footView addSubview:lastBut];
    [self.footView addSubview:nextBut];
    
    [lastLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40);
        make.centerY.mas_equalTo(0);
    }];
    
    [nextLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40);
        make.centerY.mas_equalTo(0);
    }];
    
    [lastArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.mas_equalTo(0);
        
    }];
    
    [nextArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.mas_equalTo(0);
        
    }];
    
    [lastBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(lastLab);
        make.right.equalTo(lastLab);
        make.bottom.equalTo(lastLab);
        
    }];
    
    [nextBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.top.equalTo(nextLab);
        make.left.equalTo(nextLab);
        make.bottom.equalTo(nextLab);
        
    }];
    
    
}

- (void)createHeadView{
    dateLab = [[UILabel alloc] init];
    dateLab.layer.borderColor = BangcaiOrange.CGColor;
    dateLab.backgroundColor = [UIColor colorWithRed:0.998 green:0.736 blue:0.479 alpha:1];
    dateLab.layer.masksToBounds = YES;
    dateLab.textAlignment = NSTextAlignmentCenter;
    dateLab.layer.cornerRadius = 12.5;
    dateLab.text = @"2016年06月30日";
    dateLab.font = [UIFont systemFontOfSize:14];
    dateLab.textColor = [UIColor whiteColor];
    
    position = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"定位"]];
    titleLab = [[UILabel alloc] init];
    prcice = [[UILabel alloc] init];
    
    prcice.textColor = BangcaiOrange;
    prcice.font = [UIFont systemFontOfSize:19];
    prcice.text = @"¥600";
    
    titleLab.font = [UIFont systemFontOfSize:17];
    titleLab.text = @"6个地点";
    titleLab.textColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1];
    
    distLab = [[UILabel alloc] init];
    distLab.font = [UIFont systemFontOfSize:14];
    distLab.textColor = [UIColor whiteColor];
    distLab.text = @"25km";
    distLab.backgroundColor = BangcaiOrange;
    distLab.layer.cornerRadius = 3;
    distLab.layer.masksToBounds = YES;
    
    titleLine = [[UILabel alloc] init];
    titleLine.backgroundColor = [UIColor colorWithRed:0.823 green:0.824 blue:0.823 alpha:1];
    
    orderNumLab = [[UILabel alloc] init];
    amountLab = [[UILabel alloc] init];
    weightLab = [[UILabel alloc] init];
    
    orderNumLab.textColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1];
    orderNumLab.font = [UIFont systemFontOfSize:17];
    orderNumLab.textAlignment = NSTextAlignmentLeft;
    
    amountLab.textColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1];
    amountLab.font = [UIFont systemFontOfSize:17];
    amountLab.textAlignment = NSTextAlignmentLeft;

    weightLab.textColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1];
    weightLab.font = [UIFont systemFontOfSize:17];
    weightLab.textAlignment = NSTextAlignmentRight;
    
    orderNumLab.text = @"订单号 : 20160630030005";
    amountLab.text = @"总件数 : 21件";
    weightLab.text = @"总重量 : 144公斤";
    
    widLine = [[UILabel alloc] init];
    widLine.backgroundColor = [UIColor colorWithRed:0.941 green:0.941 blue:0.941 alpha:1];
    
    
    [self.headView addSubview:dateLab];
    [self.headView addSubview:position];
    [self.headView addSubview:titleLab];
    [self.headView addSubview:distLab];
    [self.headView addSubview:titleLine];
    [self.headView addSubview:prcice];
    [self.headView addSubview:orderNumLab];
    [self.headView addSubview:amountLab];
    [self.headView addSubview:weightLab];
    [self.headView addSubview:widLine];
    [dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(140);
        make.top.mas_equalTo(12);
        
    }];
    
    [position mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(dateLab.mas_bottom).with.offset(16);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(25);
        
    }];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(position);
        make.left.mas_equalTo(position.mas_right).with.offset(12);
    }];
    
    [distLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(position);
        make.left.mas_equalTo(titleLab.mas_right).with.offset(15);
        
    }];
    
    [titleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(position.mas_bottom).with.offset(12);
        make.left.mas_equalTo(position.mas_left);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
        
    }];
    
    
    [prcice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(position);
        make.right.mas_equalTo(-12);
        
    }];

    [orderNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(titleLine.mas_bottom);
        make.height.mas_equalTo(30);
    }];
    
    [amountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(orderNumLab.mas_bottom);
        make.height.mas_equalTo(30);

    }];
    
    [weightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.top.mas_equalTo(orderNumLab.mas_bottom);
        make.height.mas_equalTo(30);

    }];
    
    [widLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(amountLab.mas_bottom).with.offset(5);
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        
    }];
}

- (void)click:(UIButton *)but
{
    NSLog(@"%@", [but class]);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.delegate click:@15151515151];
}



- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BCOrderDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.addLab.text = @"长兴市场5号门";
    cell.timeLab.text = @"06:00前送达";
    cell.amountLab.text = @"总件数 : 21件";
    cell.weightLab.text = @"重量 : 30公斤";
    if (indexPath.row == 0) {
        cell.topLine.hidden = YES;
    }else{
        cell.topLine.hidden = NO;
    }
    
    if (indexPath.row == 3) {
        cell.bottomLine.hidden = YES;
    }else{
        cell.bottomLine.hidden = NO;
    }
    return cell;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
